package com.lin.manager.controller.file;

import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.req.QueryPage;
import com.lin.manager.common.resp.R;
import com.lin.manager.file.entity.FileConfigEntity;
import com.lin.manager.file.service.FileConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @作者: 林江
 * @创建时间: 2024/3/21
 * @功能:
 */
@Api(tags = "文件配置")
@RestController
@RequestMapping("file")
public class FileConfigController {

    @Resource
    private FileConfigService fileConfigService;

    @ApiOperation("文件配置 - 分页查询")
    @Log(module = "文件配置", descipt = "分页查询", type = LogEnum.SELECT)
    @GetMapping("listPage")
    public R listPage(QueryPage page) {
        return R.ok(fileConfigService.listByPage(page));
    }

    @ApiOperation("文件配置 - 查询所有")
    @Log(module = "文件配置", descipt = "查询所有", type = LogEnum.SELECT)
    @GetMapping("list")
    public R list(QueryPage page) {
        return R.ok(fileConfigService.list());
    }

    @ApiOperation("文件配置 - 添加")
    @Log(module = "文件配置", descipt = "添加文件配置", type = LogEnum.INSERT)
    @PostMapping("add")
    public R add(@RequestBody FileConfigEntity fileConfig) {
        fileConfigService.add(fileConfig);
        return R.ok();
    }

    @ApiOperation("文件配置 - 修改")
    @Log(module = "文件配置", descipt = "修改文件配置", type = LogEnum.UPDATE)
    @PostMapping("update")
    public R update(@RequestBody FileConfigEntity fileConfig) {
        fileConfigService.update(fileConfig);
        return R.ok();
    }

    @ApiOperation("文件配置 - 修改")
    @Log(module = "文件配置", descipt = "启动文件配置", type = LogEnum.UPDATE)
    @GetMapping("updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable Integer id, @PathVariable("status") Integer status) {
        fileConfigService.updateStatus(id, status);
        return R.ok();
    }

    @ApiOperation("文件配置 - 删除")
    @Log(module = "文件配置", descipt = "删除文件配置", type = LogEnum.DELETE)
    @DeleteMapping("delete")
    public R del(Integer id) {
        fileConfigService.del(id);
        return R.ok();
    }
}
